
public class LC443M {

    public int compress(char[] chars) {
        int write=1;
        int count=1;
        int n= chars.length;
        for (int read = 1; read < n; read++) {
            if (chars[read]==chars[read-1]){
                count++;
            }
            else{
                if (count>1){
                    char[] integer=String.valueOf(count).toCharArray();
                    for (char i:integer) {
                        chars[write++]=i;
                    }
                    count=1;
                }
                chars[write++]=chars[read];
            }
            if (read==n-1 && count>1){
                char[] integer=String.valueOf(count).toCharArray();
                for (char i:integer) {
                    chars[write++]=i;
                }
            }

        }
//        System.out.println(chars);
        return write;
    }

    public static void main(String[] args) {
        String s="abbbbbbbbbbbb";
        char[] chars = s.toCharArray();
        System.out.println(new LC443M().compress(chars));
    }

}
